#include "modbus_register.h"
#include "ice_cream_control.h"

// 输入数据变量

static uint16_t trough_temp = 0;            // 料槽温度


// 输出数据变量
static uint16_t topping1 = 0;               // 顶料1
static uint16_t jam1 = 0;                   // 果酱1
static uint16_t main_compressor = 0;        // 主压机

uint16_t ac_get_current() ;
uint16_t ac_get_voltage() ;
// IO模块寄存器读取
uint16_t modbus_io_get(uint16_t address) {
    // 输入数据
    if (address == REG_X_AXIS_ORIGIN) {
        return read_x_axis_origin();
    } else if (address == REG_Z_AXIS_ORIGIN) {
        return read_z_axis_origin();
    } else if (address == REG_CUP_DETECTION) {
        return read_cup_detection();
    } else if (address==REG_CUP_FALL_MACHINE)
    {
        return read_cup_drop_pos_1();
    }else if (address==REG_FLOAT_BALL_SHORTAGE)
    {
        return read_float_material_low();
    }else if (address==REG_OPPOSING_BEAM)
    {
        return read_photoelectric_signal();
    }else if (address==REG_GRIPPER_SWITCH)
    {
        return read_gripper_switch();
    }
    else if (address == REG_TROUGH_TEMP) {
        return trough_temp;
    } else if (address == REG_VOLTAGE) {
        return ac_get_voltage();
    }else if (address == REG_CURRENT) {
        return ac_get_current();
    }
    // 输出数据
    else if (address == REG_TOPPING1) {
        return topping1;
    } else if (address == REG_JAM1) {
        return jam1;
    } else if (address == REG_MAIN_COMPRESSOR) {
        return main_compressor;
    }
    // 统计数据
    
    
    return 0;
}

// IO模块寄存器写入（仅处理输出数据）
void modbus_io_set(uint16_t address, uint16_t value) {
    // 输出数据控制
    if (address == REG_TOPPING1) {
        topping1 = value;
        // 记录顶料1使用次数

    } else if (address == REG_JAM1) {
        jam1 = value;
        // 记录果酱1使用次数

    } else if (address == REG_MAIN_COMPRESSOR) {
        main_compressor = value;
    }
    // 输入数据和统计数据通常为只读，不处理写入
}
